<!DOCTYPE html>
<html>
	{include file="public1/_header" /}
	<body>
		<div class="x-nav">
			<span class="layui-breadcrumb">
				<a href="">首页</a>
				<a>
					<cite>屏保设置</cite></a>
			</span>
			<a class="layui-btn layui-btn-small" style="float:right" onclick="location.reload()" title="刷新">
				<i class="layui-icon layui-icon-refresh" style="line-height:30px"></i>
			</a>
		</div>

		<div class="layui-fluid">
			<div class="layui-row layui-col-space15">
				<div class="layui-col-md12">
					<div class="layui-card">
						<div class="layui-card-body">

							<div class="layui-tab layui-tab-card" lay-filter="test">
								<ul class="layui-tab-title">
									<li lay-id="1" class="layui-this">文字模式</li>
									<li lay-id="2">图片模式</li>
								</ul>
								<div class="layui-tab-content">
									<div class="layui-tab-item layui-show">
										<blockquote class="layui-elem-quote layui-quote-nm">
											<form class="layui-form layui-col-space5" onsubmit="return false;" lay>
												<div class="layui-input-inline layui-show-xs-block">
													<input class="layui-input" lay-verify="required" placeholder="请输入标题" name="title" id="title1">
												</div>
												<div class="layui-input-inline layui-show-xs-block">
													<button class="layui-btn" lay-submit="" lay-filter="picSerach">查询</button>
													<button class="layui-btn  layui-btn-primary" id="picRest">重置</button>
												</div>
											</form>
										</blockquote>
										<table class="layui-hide" id="test" lay-filter="test"></table>
									</div>
									<div class="layui-tab-item">
										<blockquote class="layui-elem-quote layui-quote-nm">
											<form class="layui-form layui-col-space5" onsubmit="return false;">
												<div class="layui-input-inline layui-show-xs-block">
													<input class="layui-input" lay-verify="required" placeholder="请输入标题" name="title" id="title2">
												</div>
												<div class="layui-input-inline layui-show-xs-block">
													<button class="layui-btn" lay-submit="" lay-filter="videoSerach">查询</button>
													<button class="layui-btn  layui-btn-primary" id="videoRest">重置</button>
												</div>
											</form>
										</blockquote>
										<table class="layui-hide" id="video" lay-filter="video"></table>
									</div>
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
		<script type="text/html" id="toolbarDemo">
			<div class="layui-btn-container">
				<button class="layui-btn layui-btn-sm" lay-event="add">
					<i class="layui-icon">&#xe642;</i>清除屏保
				</button>
			</div>
		</script>
		<script type="text/javascript">
			var url = "__STATIC__/admin/"
			layui.extend({
				notice: 'notice/notice'
			}).use(['util', 'laydate', 'table', 'element', 'notice'], function() {
				var table = layui.table;
				var form = layui.form;
				var util = layui.util;
				var element = layui.element;
				var notice = layui.notice;
				var tableIns = table.render({
					id: 'testReload',
					elem: '#test',
					url: "{:url('bancard/Screensaver/lists')}",
					method: "POST",
					request: {
						pageName: 'offset', //页码的参数名称，默认：page
						limitName: 'limit' //每页数据量的参数名，默认：limit
					},
					where: {
						is_school_msg: 1,
						type: 1
					},
					toolbar: '#toolbarDemo',
					cols: [
						[  {
							field: 'title',
							title: "标题"
						}, {
							field: 'content',
							title: "内容"
						}, {
							field: 'off_time',
							title: "是否操作",
							templet: function(d) {
								if (d.off_time > 0) {
									var week = d.off_time + "分钟无操作时进入屏保"
								} else {
									var week = "永远不进入屏保"
								}

								return week;
							}
						}, {
							field: 'start_date',
							title: "日期",
							templet: function(d) {
								if (d.start_date) {
									var logoSrc = util.toDateString(d.start_date * 1000, "yyyy-MM-dd") + '~' + util.toDateString(d.end_date *
										1000, "yyyy-MM-dd");
								} else {
									var logoSrc = "--";
								}

								return logoSrc;
							},
						}, {
							field: 'end_date',
							title: "时间",
							templet: function(d) {
								if (d.start_time) {
									var logoSrc = d.start_time + '~' + d.end_time;
								} else {
									var logoSrc = "--";
								}
								return logoSrc;
							},
						}, {
							field: 'switching_data',
							title: "生效日期",
							templet: function(d) {
								var arr = d.switching_data.split(',')
								var week = ''
								arr.forEach(item => {
									if (item == 0) {
										week += '星期日,'
									} else if (item == 1) {
										week += '星期一,'
									} else if (item == 2) {
										week += '星期二,'
									} else if (item == 3) {
										week += '星期三,'
									} else if (item == 4) {
										week += '星期四,'
									} else if (item == 5) {
										week += '星期五,'
									} else if (item == 6) {
										week += '星期六,'
									}
								})
								week = week.substr(0, week.length - 1)
								return week;
							}
						}]
					],
					page: true
				});

				table.on('toolbar(test)', function(obj) {
					switch (obj.event) {
						case 'add':
							var index = parent.layer.getFrameIndex(window.name);
							var lfc = top.layerFrameConfig;
							var info = lfc.iframeB.info;
							var ids =  lfc.iframeB.ids;
							var device_ids =  lfc.iframeB.device_ids;
							var data = {};
							data.id = -1;
							data.device_ids = device_ids;
							data.ids = ids;
							$.post("{:url('push_screen')}", data, function(res) {
								if (res.code == 0) {
									layer.msg('设置成功', {
										icon: 1,
										time: 300
									}, function() {
										parent.layer.close(index); //再执行关闭
										info.reload()
									});

								} else {
									layer.msg(res.message)
									info.reload()
								}
							})
							break;
					};
				});





				//监听单元格编辑
				table.on('row(test)', function(obj) {
					var index = parent.layer.getFrameIndex(window.name);
					var lfc = top.layerFrameConfig;
					var info = lfc.iframeB.info;
					var ids =  lfc.iframeB.ids;
					var device_ids =  lfc.iframeB.device_ids;
					var data = obj.data;
					data.device_ids = device_ids;
					data.ids = ids;
					$.post("{:url('push_screen')}", data, function(res) {
						if (res.code == 0) {
							layer.msg('设置成功', {
								icon: 1,
								time: 300
							}, function() {
								parent.layer.close(index); //再执行关闭
								info.reload()
							});
									
						} else {
							layer.msg(res.message)
							info.reload()
						}
					})

				});
				//监听单元格编辑
				table.on('row(video)', function(obj) {
					var index = parent.layer.getFrameIndex(window.name);
					var lfc = top.layerFrameConfig;
					var info = lfc.iframeB.info;
					var ids =  lfc.iframeB.ids;
					var device_ids =  lfc.iframeB.device_ids;
					var data = obj.data;
					data.device_ids = device_ids;
					data.ids = ids;
					$.post("{:url('push_screen')}", data, function(res) {
						if (res.code == 0) {
							layer.msg('设置成功', {
								icon: 1,
								time: 300
							}, function() {
								parent.layer.close(index); //再执行关闭
								info.reload()
							});
									
						} else {
							layer.msg(res.message)
							info.reload()
						}
					})
				
				});

				element.on('tab(test)', function(data) {
					var videoIns = table.render({
						id: 'videoReload',
						elem: '#video',
						url: "{:url('bancard/Screensaver/lists')}",
						method: "POST",
						request: {
							pageName: 'offset', //页码的参数名称，默认：page
							limitName: 'limit' //每页数据量的参数名，默认：limit
						},
						where: {
							is_school_msg: {$Think.session.schoolInfo.id},
							type: 2
						},
						toolbar: '#toolbarDemo',
						cols: [
							[ {
								field: 'title',
								title: "标题"
							}, {
								field: 'pics',
								title: "相册",
								sort: true,
								templet: function(d) {
									var logoSrc = "";
									layui.each(d.pics, function(index, item) {
										logoSrc += "<img src='" + item.thumb +
											"'  width='35' height='26' style='border:1px solid #ccc;box-sizing:border-box' />";
									})
									return logoSrc;
								},
								event: "nameClick"
							}, {
								field: 'off_time',
								title: "是否操作",
								templet: function(d) {
									if (d.off_time > 0) {
										var week = d.off_time + "分钟无操作时进入屏保"
									} else {
										var week = "永远不进入屏保"
									}

									return week;
								}
							}, {
								field: 'start_date',
								title: "日期",
								templet: function(d) {
									if (d.start_date) {
										var logoSrc = util.toDateString(d.start_date * 1000, "yyyy-MM-dd") + '~' + util.toDateString(d.end_date *
											1000, "yyyy-MM-dd");
									} else {
										var logoSrc = "--";
									}

									return logoSrc;
								},
							}, {
								field: 'end_date',
								title: "时间",
								templet: function(d) {
									if (d.start_time) {
										var logoSrc = d.start_time + '~' + d.end_time;
									} else {
										var logoSrc = "--";
									}
									return logoSrc;
								},
							}, {
								field: 'switching_data',
								title: "生效日期",
								templet: function(d) {
									var arr = d.switching_data.split(',')
									var week = ''
									arr.forEach(item => {
										if (item == 0) {
											week += '星期日,'
										} else if (item == 1) {
											week += '星期一,'
										} else if (item == 2) {
											week += '星期二,'
										} else if (item == 3) {
											week += '星期三,'
										} else if (item == 4) {
											week += '星期四,'
										} else if (item == 5) {
											week += '星期五,'
										} else if (item == 6) {
											week += '星期六,'
										}
									})
									week = week.substr(0, week.length - 1)
									return week;
								}
							}]
						],
						page: true
					});
					
					
					
				});


				
				
				form.on('submit(picSerach)', function(data) {
					//执行重载
					table.reload('testReload', {
						method: "POST",
						request: {
							pageName: 'offset', //页码的参数名称，默认：page
							limitName: 'limit' //每页数据量的参数名，默认：limit
						},
						where: {
							type: 1,
							is_school_msg: {$Think.session.schoolInfo.id},
							keywords: data.field.title,
						},
						page: {
							curr: 1 //重新从第 1 页开始
						}
					});
					return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
				});
				form.on('submit(videoSerach)', function(data) {
					//执行重载
					table.reload('videoReload', {
						method: "POST",
						request: {
							pageName: 'offset', //页码的参数名称，默认：page
							limitName: 'limit' //每页数据量的参数名，默认：limit
						},
						where: {
							type: 2,
							is_school_msg: {$Think.session.schoolInfo.id},
							keywords: data.field.title,
						},
						page: {
							curr: 1 //重新从第 1 页开始
						}
					});
					return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
				});

				
				$(function() {

					$("#picRest").click(function() {
						//执行重载
						$("#title1").val("");
						table.reload('testReload', {
							method: "POST",
							request: {
								pageName: 'offset', //页码的参数名称，默认：page
								limitName: 'limit' //每页数据量的参数名，默认：limit
							},
							where: {
								type: 1,
								is_school_msg: {$Think.session.schoolInfo.id},
								keywords: "",
							},
							page: {
								curr: 1 //重新从第 1 页开始
							}
						});
						return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。

					})
					$("#videoRest").click(function() {
						$("#title2").val("");
						//执行重载
						table.reload('videoReload', {
							method: "POST",
							request: {
								pageName: 'offset', //页码的参数名称，默认：page
								limitName: 'limit' //每页数据量的参数名，默认：limit
							},
							where: {
								type: 2,
								is_school_msg: {$Think.session.schoolInfo.id},
								keywords: "",
							},
							page: {
								curr: 1 //重新从第 1 页开始
							}
						});
						return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。

					})

				})
			});
		</script>
	</body>
</html>
